"""
@file : homework
@author : wujiaxi
@Date : 2021/7/27

"""
#第一题  map批量检测用户名，字母数字下划线，不能以数字开头，长度在6-18之间
username_list = ["nanfeng123_321","3248dhasuhd_487","dqweqdwfet652646_5235","e42_3","dsq130-===?dshu","beihai_3124you"]
def func1(x):
    for i in x:
        error_list = [0,0,0]
        if i.isalnum() or i == "_":
            error_list[0] = 0
        else:
            error_list[0] = 1
            break
    if x[1].isdigit():
        error_list[1] = 1
    if len(x) >= 18 or len(x) <= 6:
        error_list[2] = 1

    if sum(error_list) > 0:
        return False
    else:
        return True

print("合法的用户名为:",list(filter(func1, username_list)))


#2
from functools import reduce
n = input("请输入累乘的最后一位数n：")
print(reduce(lambda x,y:x*y ,range(1,int(n) + 1)))

#3
print(list(filter(lambda x:x%3 == 0,range(1,101))))


#4
print(list(map(lambda x:x**2,range(1,11))))


#5
from functools import reduce
lst = [1,4,5,9]
map(lambda x:str(x),lst)
print(reduce(lambda x,y:x+y,map(lambda x:str(x),lst)))



# 6 list = [7,-8,5,4,0,-2,-5]

list = [7,-8,5,4,0,-2,-5]
lst0 = sorted(list)

a = 0

for i in range(len(lst0)):
    if lst0[i] == 0 :
        lst1 = lst0[0:i]
        lst2 = lst0[i+1:len(lst0)]
        a = 1
        break
    elif lst0[i] > 0:
        lst1 = lst0[0:i]
        lst2 = lst0[i:len(lst0)]

lst1 = sorted(lst1,reverse = True)
if a == 0:
    print(lst2+lst1)
else:
    print(lst2 + [0] + lst1)


# 7
from functools import reduce

S = "asdf234GDSdsf23"
upper_alpha = []
lower_alpha =[]
odd_num = []
complex_num = []

for i in S:
    if i.isalpha():
        if i.isupper():
            upper_alpha.append(i)
        elif i.islower():
            lower_alpha.append(i)
    elif i.isdigit():
        if int(i)%2 == 1:
            odd_num.append(i)
        if int(i)%2 == 0:
            complex_num.append(i)

upper_alpha = sorted(upper_alpha)
lower_alpha = sorted(lower_alpha)
odd_num = sorted(odd_num)
complex_num = sorted(complex_num)
all_lst = lower_alpha + upper_alpha + odd_num + complex_num
print(all_lst)

print(reduce(lambda x,y:x + y ,all_lst))